def add(a, b):
    return a + b

def subtract(a, b):
    return a - b

def multiply(a, b):
    return a * b

def divide(a, b):
    if b == 0:
        raise ValueError("除数不能为零")
    return a / b

def main():
    print("=== 简单计算器 ===")
    print("支持的运算：")
    print("1. 加法")
    print("2. 减法")
    print("3. 乘法")
    print("4. 除法")
    print("5. 返回主菜单")
    
    while True:
        try:
            choice = input("\n请选择运算类型 (1-5): ")
            
            if choice == '5':
                break
                
            if choice not in ['1', '2', '3', '4']:
                print("无效的选择，请重试")
                continue
                
            num1 = float(input("请输入第一个数字: "))
            num2 = float(input("请输入第二个数字: "))
            
            if choice == '1':
                result = add(num1, num2)
                print(f"\n{num1} + {num2} = {result}")
            elif choice == '2':
                result = subtract(num1, num2)
                print(f"\n{num1} - {num2} = {result}")
            elif choice == '3':
                result = multiply(num1, num2)
                print(f"\n{num1} * {num2} = {result}")
            elif choice == '4':
                try:
                    result = divide(num1, num2)
                    print(f"\n{num1} / {num2} = {result}")
                except ValueError as e:
                    print(f"\n错误：{str(e)}")
                    
        except ValueError:
            print("\n请输入有效的数字")
            
if __name__ == '__main__':
    main()